package com.ruoyi.project.dict.chengyutag.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.dict.chengyutag.domain.ChengyuTag;
import com.ruoyi.project.dict.chengyutag.service.IChengyuTagService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.domain.Ztree;

/**
 * 成语标签Controller
 * 
 * @author shixiangwen
 * @date 2021-12-01
 */
@Controller
@RequestMapping("/dict/chengyutag")
public class ChengyuTagController extends BaseController
{
    private String prefix = "dict/chengyutag";

    @Autowired
    private IChengyuTagService chengyuTagService;

    @RequiresPermissions("dict:chengyutag:view")
    @GetMapping()
    public String chengyutag()
    {
        return prefix + "/chengyutag";
    }

    /**
     * 查询成语标签树列表
     */
    @RequiresPermissions("dict:chengyutag:list")
    @PostMapping("/list")
    @ResponseBody
    public List<ChengyuTag> list(ChengyuTag chengyuTag)
    {
        List<ChengyuTag> list = chengyuTagService.selectChengyuTagList(chengyuTag);
        return list;
    }

    /**
     * 导出成语标签列表
     */
    @RequiresPermissions("dict:chengyutag:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ChengyuTag chengyuTag)
    {
        List<ChengyuTag> list = chengyuTagService.selectChengyuTagList(chengyuTag);
        ExcelUtil<ChengyuTag> util = new ExcelUtil<ChengyuTag>(ChengyuTag.class);
        return util.exportExcel(list, "chengyutag");
    }

    /**
     * 新增成语标签
     */
    @GetMapping(value = { "/add/{tagId}", "/add/" })
    public String add(@PathVariable(value = "tagId", required = false) Long tagId, ModelMap mmap)
    {
        if (StringUtils.isNotNull(tagId))
        {
            mmap.put("chengyuTag", chengyuTagService.selectChengyuTagById(tagId));
        }
        return prefix + "/add";
    }

    /**
     * 新增保存成语标签
     */
    @RequiresPermissions("dict:chengyutag:add")
    @Log(title = "成语标签", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ChengyuTag chengyuTag)
    {
        return toAjax(chengyuTagService.insertChengyuTag(chengyuTag));
    }

    /**
     * 修改成语标签
     */
    @GetMapping("/edit/{tagId}")
    public String edit(@PathVariable("tagId") Long tagId, ModelMap mmap)
    {
        ChengyuTag chengyuTag = chengyuTagService.selectChengyuTagById(tagId);
        mmap.put("chengyuTag", chengyuTag);
        return prefix + "/edit";
    }

    /**
     * 修改保存成语标签
     */
    @RequiresPermissions("dict:chengyutag:edit")
    @Log(title = "成语标签", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ChengyuTag chengyuTag)
    {
        return toAjax(chengyuTagService.updateChengyuTag(chengyuTag));
    }

    /**
     * 删除
     */
    @RequiresPermissions("dict:chengyutag:remove")
    @Log(title = "成语标签", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{tagId}")
    @ResponseBody
    public AjaxResult remove(@PathVariable("tagId") Long tagId)
    {
        return toAjax(chengyuTagService.deleteChengyuTagById(tagId));
    }

    /**
     * 选择成语标签树
     */
    @GetMapping(value = { "/selectChengyutagTree/{tagId}", "/selectChengyutagTree/" })
    public String selectChengyutagTree(@PathVariable(value = "tagId", required = false) Long tagId, ModelMap mmap)
    {
        if (StringUtils.isNotNull(tagId))
        {
            mmap.put("chengyuTag", chengyuTagService.selectChengyuTagById(tagId));
        }
        return prefix + "/tree";
    }

    /**
     * 加载成语标签树列表
     */
    @GetMapping("/treeData")
    @ResponseBody
    public List<Ztree> treeData()
    {
        List<Ztree> ztrees = chengyuTagService.selectChengyuTagTree();
        return ztrees;
    }
}
